﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@using Wantn.FIS.Enum
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
    //岩相管理
}

<div id="uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
    <form name="form1" method="post" id="form1">
        <table>
            <tr>
                <th style="padding:20px; "> Excel：</th>
                <td style="padding:20px; ">
                    <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                    <a href="javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                    <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                    <span class="uploading">@Resource.Uploading</span>
                </td>
            </tr>
        </table>
        <div class="endbtndiv">
            <a id="btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
            <a id="btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
        </div>
    </form>
</div>
<div class="mvctool">
    @*<input id="txtTestCode" type="text" class="searchText" placeholder="化验编码" />*@
    @Html.DropDownList("queryState", EnumMvcHelper.GetMVCSelectList<ApprovalStatus>("审批状态"), new { @style = "width:100px;" })
    <input id="txtBatchCode" type="text" class="searchText" placeholder="批次编码" />
    <select class="easyui-combobox" name="BATCH_TYPE" id="BATCH_TYPE" style="width:120px;">
        <option value="">=== 全部类别 ===</option>
        <option value="入厂煤">入厂煤</option>
        <option value="自采煤">其他</option>
    </select>
    <select class="easyui-combobox" name="TYPE_ID" id="TYPE_ID" style="width:120px;"></select>
    <select class="easyui-combobox" name="MATERIEL_ID" id="MATERIEL_ID" style="width:120px;"></select>
    <select class="easyui-combobox" name="isJsuan" id="isJsuan" style="width:120px;">
        <option value="">===结算状态===</option>
        <option value="是">是</option>
        <option value="否">否</option>
    </select>
    <select class="easyui-combobox" name="jsRelated" id="jsRelated" style="width:120px;">

        <option value="">===关联状态===</option>
        <option value="是">是</option>
        <option value="否">否</option>
    </select>
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @*@Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
        @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)*@
    @Html.ToolButton("btnExamine", "fa fa-check", "关联", ref perm, "Examine", true)
    @Html.ToolButton("btnUnExamine", "fa fa-check", "取消关联", ref perm, "UnExamine", true)
    @Html.ToolButton("btnJieSuanData", "fa fa-check", "结算", ref perm, "JieSuanData", true)
    @Html.ToolButton("btnUnJieSuanData", "fa fa-check", "取消结算", ref perm, "UnJieSuanData", true)
    @*@Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", true)*@

</div>
<table id="List"></table>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">


    $(function () {

        $.ajax({
            url: '../../RC/SAMPLING/GetTranSuppList?type=4',
            type: 'post',
            dataType: 'json',
            success: function (result) {
                $('#TYPE_ID').combobox({
                    data: result,
                    valueField: 'Value',
                    textField: 'Text',
                    onLoadSuccess: function () {

                    }
                });
            },
        });

         GetTranSuppList(2, "@ViewBag.MATERIEL_ID");
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'ADDTIME',
            sortOrder: 'desc',
            idField: 'ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            selectOnCheck: false,
            checkOnSelect: false,
            checkbox: true,
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                $("#List").datagrid("clearSelections"); //全部不选中
                $("#List").datagrid("clearChecked"); //全部不选中
                $("#List").datagrid("unselectAll"); //全部不选中
            },
            columns: [[
                {
                    field: 'ck', title: '编号', width: '40px', title: ' ',
                    formatter: function (value, row) {
                        if (row.APPROVAL_STATUS != 3) {
                            return '';
                        }
                        if (row.TYPE_STR == '小焦炉煤') {
                            return '';
                        }
                        if (row.TYPE_STR == '小焦炉焦炭') {
                            return '';
                        }
                        return '<div style="" class="datagrid-cell-check"><input type="checkbox" name="ck" value=""></div>';
                    }
                },
                { field: 'APPROVAL_STATUS', title: '审批状态', width: 80, sortable: true, formatter: @Html.Raw(GridHelper.GridFormatterFunc<ApprovalStatus>("gConvertApprovalStatus")) },
                { field: 'SELF_BATCH_CODE', title: '关联化验码', width: '145px', align: 'center', styler: cellStyler },
                { field: 'ISJSUAN', title: '结算状态', width: '70px', align: 'center', styler: cellStyler },
                { field: 'BATCH_TYPE', title: '批次类型', width: '80px' },
                { field: 'BATCH_CODE', title: '批次码', width: '100px' },
                { field: 'TEST_CODE', title: '化验码', width: '100px' },
                { field: 'TYPE_STR', title: '类型', width: 100, sortable: true },
                { field: 'MATERIEL_NAME', title: '物料', width: 140 },
                /*{ field: 'MINE_NAME', title: '煤种', width: 140 },*/
                { field: 'STR_COLLECT_TIME', title: '收样时间', width:140 },
                //{ field: 'TRANSPORT_NAME', title: '运输商', width: '10%' },

                { field: 'CRI', title: 'CRI%', width: 80 },
                { field: 'CSR', title: 'CSR%', width:80 },
                { field: 'YANX_VALUE', title: '岩相', width: 80 },
                { field: 'MT', title: 'Mt(%)', width: 80 },
                { field: 'MAD', title: 'Mad(%)', width: 80 },
                { field: 'AD', title: 'Ad(%)', width: 80 },
                { field: 'VDAF', title: 'Vdaf(%)', width: 80 },
                { field: 'STD', title: 'St,d(%)', width: 80 },
                { field: 'G', title: 'G(%)', width: 80 },
                { field: 'Y', title: 'Y(%)', width: 80 },
                { field: 'X', title: 'X(%)', width: 80 },
                { field: 'A', title: 'a(%)', width: 80 },
                { field: 'B', title: 'b(%)', width: 80 },
                { field: 'QNETAR_KCAL', title: 'Qnet,ar（kcal/kg)', width: 120 },
                //新增字段 BEGIN
                { field: 'SMEDIUN', title: '<0.5mm(%)', width: 80 },
                { field: 'SMALL', title: '<3mm(%)', width: 80 },
                { field: 'MEDIUM', title: '3~10mm(%)', width: 80 },
                { field: 'LARGE', title: '>10mm(%)', width: 80 },
                //{ field: 'CRI', title: 'CRI(%)', width: 80 },
                //{ field: 'CSR', title: 'CSR(%)', width: 80 },
                { field: 'M40', title: 'M40(%)', width: 80 },
                { field: 'M10', title: 'M10(%)', width: 80 },
                { field: 'JTXXLARGE', title: '>80mm(%)', width: 80 },
                { field: 'JTXLARGE', title: '80~60mm%)', width: 80 },
                { field: 'JTLARGE', title: '60~40mm%)', width: 80 },
                { field: 'JTMEDIUM', title: '40~25mm(%)', width: 80 },
                { field: 'JTSMALL', title: '<25mm(%)', width: 80 },
                //{ field: 'ADDTIME', title: '操作时间', width: 120, sortable: true }
            ]], onClickRow: function (index, row) {


            }

        });
    });

    function cellStyler(value, row, index) {
        if (value == '是') {
            return 'color:#FF5722; text-align:center';
        }
        if (value != '' && value != undefined) {
            return 'color:#FF5722; text-align:center';
        }
    }
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }

    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');

        $("#List").datagrid("clearSelections"); //全部不选中
        $("#List").datagrid("clearChecked"); //全部不选中
        $("#List").datagrid("unselectAll"); //全部不选中
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("Create")'></iframe>");
            $("#modalwindow").window({ title: Lang.Create, width: 900, height: 550, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%' frameborder='0' src='@Url.Action("Edit")?id=" + row.YAN_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 900, height: 600, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnQuery").click(function () {

            $("#List").datagrid("load", {
                //txtTestCode txtBatchCode txtName
                materielName: $("#MATERIEL_ID").combobox('getText').toString(),
                batchCode: $("#txtBatchCode").val(),
                isJsuan: $("#isJsuan").combobox('getText').toString(),
                jsRelated: $("#jsRelated").combobox('getText').toString(),
                BatchType: $("#BATCH_TYPE").combobox('getValues').toString(),
                ApprovalStatus: $("#queryState").val(),
                TypeStr: $("#TYPE_ID").combobox('getValues').toString(),
            });

        });
        $("#btnExamine").click(function () {
             var formRow = $('#List').datagrid('getChecked');

            if (formRow != null && formRow.length > 0) {
                if (formRow.length > 15) {
                    { $.messageBox5s(Lang.Tip, '一次最多关联15条记录'); }
                    return;
                }
                 var formIds = ""
                $.each(formRow, function (i, row) {
                    /* if (row.AUDIT_STATUS !="审核通过") {*/
                    if (1==1) {
                       if (formIds == "")
                        {
                           formIds = row.BATCH_CODE;
                        }
                        else {
                           formIds = formIds + "," + row.BATCH_CODE;
                        }
                    }
                });

                if (formIds == "") {
                    $.messageBox5s(Lang.Tip, '没有可关联记录');
                    return;
                }
                else {
                    console.log('@Url.Action("Examine")', 'sss');
                    $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Examine")?dataIds=" + formIds + "'></iframe>");
                    $("#modalwindow").window({ title: '关联', width: 400, height: 600, iconCls: 'fa fa-pencil' }).window('open');
                }
            }
            else
                {$.messageBox5s(Lang.Tip, '请至少选择一条记录');}
        });
        $("#btnUnExamine").click(function () {
            var formRow = $('#List').datagrid('getChecked');

           if (formRow != null && formRow.length > 0) {
               if (formRow.length > 15) {
                   { $.messageBox5s(Lang.Tip, '一次最多15条记录'); }
                   return;
               }
               var formIds = ""
               $.each(formRow, function (i, row) {
                   /* if (row.AUDIT_STATUS !="审核通过") {*/
                   if (1==1) {
                      if (formIds == "")
                       {
                          formIds = row.BATCH_CODE;
                       }
                       else {
                          formIds = formIds + "," + row.BATCH_CODE;
                       }
                   }
               });

               if (formIds == "") {
                   $.messageBox5s(Lang.Tip, '请选择记录');
                   return;
               }
               else {
                 $.messager.confirm(index_lang_tip, '您确定取消关联已选批次?', function (r) {
                  if (r) {
                         $.ajax({
                          url: "@Url.Action("UnExamine")",
                          type: "Post",
                          data: { dataIds: formIds },
                          dataType: "json",
                          success: function (data) {
                              if (data.type == 1) {
                                 frameReturnByMes(data.message);
                                 frameReturnByReload(true);
                                 frameReturnByClose()
                              }
                              else {
                                 frameReturnByMes(data.message);
                              }
                          }
                      });
                  }
                 });


               }
           }
           else
               {$.messageBox5s(Lang.Tip, '请至少选择一条记录');}
        });

        //
        $("#btnJieSuanData").click(function () {
          var formRow = $('#List').datagrid('getChecked');

         if (formRow != null && formRow.length > 0) {
             if (formRow.length > 15) {
                 { $.messageBox5s(Lang.Tip, '一次最多结算15条记录'); }
                 return;
             }
              var formIds = ""
             $.each(formRow, function (i, row) {
                 /* if (row.AUDIT_STATUS !="审核通过") {*/
                 if (1==1) {
                    if (formIds == "")
                     {
                        formIds = row.BATCH_CODE;
                     }
                     else {
                        formIds = formIds + "," + row.BATCH_CODE;
                     }
                 }
             });

             if (formIds == "") {
                 $.messageBox5s(Lang.Tip, '没有可结算记录');
                 return;
             }
             else {
                 $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("JieSuan")?dataIds=" + formIds + "'></iframe>");
                 $("#modalwindow").window({ title: '结算', width: 400, height: 600, iconCls: 'fa fa-pencil' }).window('open');
             }
         }
         else
             {$.messageBox5s(Lang.Tip, '请至少选择一条记录');}
             });

        $("#btnUnJieSuanData").click(function () {
             var formRow = $('#List').datagrid('getChecked');

            if (formRow != null && formRow.length > 0) {
                if (formRow.length > 15) {
                    { $.messageBox5s(Lang.Tip, '一次最多取消15条记录'); }
                    return;
                }
                var formIds = ""
                $.each(formRow, function (i, row) {
                    /* if (row.AUDIT_STATUS !="审核通过") {*/
                    if (1==1) {
                       if (formIds == "")
                        {
                           formIds = row.BATCH_CODE;
                        }
                        else {
                           formIds = formIds + "," + row.BATCH_CODE;
                        }
                    }
                });

                if (formIds == "") {
                    $.messageBox5s(Lang.Tip, '请选择记录');
                    return;
                }
                else {
                  $.messager.confirm(index_lang_tip, '您确定取消结算状态?', function (r) {
                   if (r) {
                          $.ajax({
                           url: "@Url.Action("UnJieSuanData")",
                           type: "Post",
                           data: { dataIds: formIds },
                           dataType: "json",
                           success: function (data) {
                               if (data.type == 1) {
                                  frameReturnByMes(data.message);
                                  frameReturnByReload(true);
                                  frameReturnByClose()
                               }
                               else {
                                  frameReturnByMes(data.message);
                               }
                           }
                       });
                   }
                  });


                }
            }
            else
                {$.messageBox5s(Lang.Tip, '请至少选择一条记录');}
         });



        $("#btnDelete").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm(index_lang_tip, '@Resource.YouWantToDeleteTheSelectedRecords', function (r) {
                    if (r) {
                        $.post("@Url.Action("Delete")?id=" + row.YAN_ID, function (data) {
                            if (data.type == 1)
                                $("#List").datagrid('load');
                            $.messageBox5s(Lang.Tip, data.message);
                        }, "json");
                    }
                });
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
    });
</script>

